package com.lc.activiti.utils;

import com.lc.activiti.sys.entity.SysUser;
import com.lc.activiti.sys.service.SysUserService;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import javax.annotation.Resource;
import java.util.Collections;

/**
 * @Title: ActivitiUserDetailsManager
 * @Description:
 * @author: 骆超
 * @date: 2021/6/9 14:26
 */
public class ActivitiUserDetailsManager implements UserDetailsService {

    @Resource
    SysUserService userService;

    @Override
    public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException {
        SysUser sysUser = userService.getById(userId);
        return new User(sysUser.getName(), "", Collections.singletonList(new SimpleGrantedAuthority("ROLE_ACTIVITI_USER")));
    }
}
